<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    //this关键字的指向，也是根据当前对象（运行环境）而定的
    var a="123";//全局变量
    function sum(a) {
        console.log(this.a);
        console.log(this==window);
    }
//    sum(10);//123
//    sum({a:20});//123
//    sum.call({a:20});//20 call可以固定this指针，指向当前的运行环境
    sum.apply(this,[{a:20}]);//123



    function fn (a, b) {
        console.log(a + b);
    }

    //在全局环境中运行
    fn.call(this, 5, 8);
    //apply方法和call功能一样，就是参数换成了数组
    fn.apply(this, [6, 9]);



</script>
</body>
</html>